﻿@model KL.Store.Web.Models.ProductModel
@using KL.Store.Core;
@using CaptchaMvc.HtmlHelpers;
@{
    Layout = null;
    ViewBag.Title = "Edit Product Images";
    //Html.EnableClientValidation(false);

    var ver = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString(); 
}
<div class="col-xs-12 first last aligncenter" id="imageEditList">
    <ul>
        @foreach (var img in Model.ProductImages.Select(o => o.ProductId).Distinct())
        {
            for (var i = 1; i <= 5; i++)
            {
                var itsAvailable = false;
                if (Model.ProductImages.Where(o => o.ImageId == i).Count() > 0)
                {
                    itsAvailable = true;
                }
            <li class="image" id="img@(img)_@(i)">
                @if (itsAvailable)
                {
                    <img src="@(Parameters.WebSiteImageUrl)/product-medium/@(img)_@(i).jpg?v=@(ver)" onclick="SelectImage(@img, @i);" />
                    <span class="editImageSlotText">Slot @i <i onclick="RemoveProductImage(@(img), @(i));" class="glyphicon glyphicon-remove" title="Resimi sil" style="cursor: pointer;"></i></span>

                }
                else
                {
                    <div class="editImageNotFound" onclick="SelectImage(@img, @i);">Resim Yok</div>
                    <span class="editImageSlotText">Slot @i</span>

                }
            </li>
            }
        }
    </ul>
</div>
<div class="col-xs-12 first">
    <div id="ShowImage">
        @{Html.RenderAction("UploadMultipleProductImages", "Upload", new { id = @Model.ProductId, });}
    </div>
</div>
<script>
    function SelectImage(id, imageId)
    {
        $('#ShowImage').load('/Upload/ShowImage', { id: id, imageId: imageId }, function ()
        {
            if ($.browser.webkit)
            {
                $('body:not(:animated)').animate({ scrollTop: 0 }, 'slow');
            }
            else
            {
                $('html:not(:animated)').animate({ scrollTop: 0 }, 'slow');
            }
        });
    }
    function RemoveProductImage(productId, imageId)
    {
        if (confirm('Silmek istediğinizden emin misiniz?'))
        {
            $('#imgProcessResult').load("/Upload/DeleteProductImage2", { productId: productId, ImageNo: imageId, Password: '@(ViewBag.Password)', ImageType: 'Product' }, function ()
            {
                var result = $('#imgProcessResult').html();
                if (result == 'Resim Silindi.')
                {
                    location.reload(true);
                }
                else
                {
                    alert(result);
                }
                $('#imgProcessResult').html('');
            });
        }
    }
    //$(document).ready(function ()
    //{
    //    $('#imageEditList img').each(function ()
    //    {
    //        var src = $(this).attr('src');
    //        $(this).attr('src', src+'?timestamp=' + new Date().getTime());
    //    });
    //});

</script>
<div style="display: none;" id="imgProcessResult"></div>
